/**
 * 
 */
package com.mc.yingshi;

import java.io.IOException;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * 摄像头
 * @author w.weizhen
 *
 */
public class Camera {
	private static String accessToken="at.0pzhbb9ybynpql9d98k2b0t07piuy9uu-2a3k2tdbzn-147ns5n-nm4jpby6x";
    private static String cameraList="https://open.ys7.com/api/lapp/camera/list";//获取摄像头列表
    /**
     * @param args
     */
    public static void main(String[] args) {
    	list();
    	
    }
    //获取摄像头列表
    private static void list(){
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody requestBody = new FormBody.Builder()
            .add("accessToken", accessToken)
            .add("pageStart", "1")
            .add("pageSize", "50")
            .build();
        Request request = new Request.Builder()
            .url(cameraList)
            .post(requestBody)
            .build();
        Call call = okHttpClient.newCall(request);
        try {
            Response response = call.execute();
            String responseBody = response.body().string();
            System.out.println(responseBody);
            
            JSONObject body = JSON.parseObject(responseBody);
            JSONArray datas = body.getJSONArray("data");
            
            for (int i = 0; i < datas.size(); i++) {
                //在线
                if ("1".equals(datas.getJSONObject(i).getString("status"))) {
                    System.out.println(datas.getJSONObject(i).getString("deviceSerial")+" 在线;");
                }
                //不在线
                if ("0".equals(datas.getJSONObject(i).getString("status"))) {
                    System.out.println(datas.getJSONObject(i).getString("deviceSerial")+" 不在线;");
                }
                //设备未上报
                if ("-1".equals(datas.getJSONObject(i).getString("status"))) {
                    System.out.println(datas.getJSONObject(i).getString("deviceSerial")+" 设备未上报;");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
